package com.esri.android.map.popup;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import com.esri.android.map.MapView;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.Feature;
import com.esri.core.map.FeatureType;
import com.esri.core.map.Graphic;
import com.esri.core.map.popup.PopupInfo;
import java.io.File;
import java.util.List;
import java.util.Map;

/* loaded from: classes.dex */
public class Popup {
    PopupInfo a;
    Feature b;
    UserCredentials c;
    private a d;
    private boolean e;
    private PopupLayout f;
    private InternalPopupListener g;
    private PopupListener h;
    private boolean i;
    private boolean j;
    private boolean k;
    private Context l;
    protected FeatureType mFeatureType;

    /* loaded from: classes.dex */
    interface InternalPopupListener {
        void onChangedEditMode(boolean z);
    }

    /* loaded from: classes.dex */
    public interface PopupListener {
        void onPopupModified();

        void onPopupValidityChanged(boolean z);
    }

    public void setCredentials(UserCredentials userCredentials) {
        this.c = userCredentials;
    }

    public PopupInfo getPopupInfo() {
        return this.a;
    }

    public PopupLayout getLayout() {
        return this.f;
    }

    public void setLayout(PopupLayout popupLayout) {
        this.f = popupLayout;
    }

    @Deprecated
    public Graphic getGraphic() {
        Feature feature = this.b;
        if (feature == null || !(feature instanceof Graphic)) {
            return null;
        }
        return (Graphic) feature;
    }

    public Feature getFeature() {
        return this.b;
    }

    public boolean isEditable() {
        return this.i;
    }

    public boolean isDeletable() {
        return this.j;
    }

    public boolean isAllowGeometryUpdate() {
        return this.k;
    }

    public void setEditable(boolean z) {
        this.i = z;
    }

    public void setDeletable(boolean z) {
        this.j = z;
    }

    public void setAllowGeometryUpdate(boolean z) {
        this.k = z;
    }

    public static String getPopupString(String str, String str2, Context context) {
        if (str == null || context == null) {
            return null;
        }
        Resources resources = context.getApplicationContext().getResources();
        int identifier = resources.getIdentifier(str, "string", context.getApplicationContext().getPackageName());
        return identifier == 0 ? str2 : resources.getString(identifier);
    }

    public static String getPopupString(String str, Context context) {
        return getPopupString(str, null, context);
    }

    public Popup(MapView mapView, Feature feature) {
        this(mapView, null, feature);
    }

    public Popup(MapView mapView, PopupInfo popupInfo, Feature feature) {
        this(mapView, popupInfo, feature, a(mapView.getContext()), true);
    }

    public Popup(MapView mapView, PopupInfo popupInfo, Feature feature, PopupLayout popupLayout) {
        this(mapView, popupInfo, feature, popupLayout == null ? a(mapView.getContext()) : popupLayout, true);
    }

    public Popup(MapView mapView, PopupInfo popupInfo, Feature feature, PopupLayout popupLayout, boolean z) {
        this(mapView, popupInfo, feature, popupLayout, z, null);
    }

    public Popup(MapView mapView, PopupInfo popupInfo, Feature feature, PopupLayout popupLayout, boolean z, UserCredentials userCredentials) {
        this(mapView.getContext(), popupInfo, feature, popupLayout == null ? a(mapView.getContext()) : popupLayout);
        this.c = userCredentials;
        if (z) {
            a(mapView);
        }
    }

    private static PopupLayoutInfo a(Context context) {
        PopupLayoutInfo popupLayoutInfo = new PopupLayoutInfo();
        PopupDefaultLayout popupDefaultLayout = new PopupDefaultLayout(context);
        popupLayoutInfo.setLayout(popupDefaultLayout);
        popupLayoutInfo.setAttachmentsViewPlaceHolder(popupDefaultLayout.d);
        popupLayoutInfo.setAttributesViewPlaceHolder(popupDefaultLayout.b);
        popupLayoutInfo.setMediaViewPlaceHolder(popupDefaultLayout.c);
        popupLayoutInfo.setTitleViewPlaceHolder(popupDefaultLayout.a);
        return popupLayoutInfo;
    }

    private void a(MapView mapView) {
        this.f.setTitleView(new ArcGISTitleView(this.l, this, mapView));
        this.f.setAttributesView(new ArcGISAttributeView(this.l, this));
        this.f.setMediaView(new ArcGISMediaView(this.l, this));
        this.f.setAttachmentsView(new ArcGISAttachmentsView(this.l, this));
    }

    @Deprecated
    public Popup(Context context, PopupInfo popupInfo, Feature feature, PopupLayout popupLayout) {
        this.d = null;
        this.e = false;
        this.i = false;
        this.j = false;
        this.k = false;
        this.l = context;
        this.a = popupInfo;
        this.b = feature;
        this.f = popupLayout;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public a a() {
        if (this.d == null) {
            a aVar = new a(this.l, this.f);
            this.d = aVar;
            aVar.a(this.e);
            this.d.a();
        }
        return this.d;
    }

    public void refresh() {
        a aVar = this.d;
        if (aVar != null) {
            aVar.a();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void b() {
        this.d.removeAllViews();
        this.d = null;
    }

    public boolean isEditMode() {
        return this.e;
    }

    public Map<String, Object> getUpdatedAttributes() {
        if (this.f.getAttributesView() == null || !(this.f.getAttributesView() instanceof AttributeView)) {
            return null;
        }
        return ((AttributeView) this.f.getAttributesView()).getUpdatedAttributes();
    }

    public void addAttachment(Uri uri) {
        if (this.f.getAttachmentsView() == null || !(this.f.getAttachmentsView() instanceof AttachmentView)) {
            return;
        }
        ((AttachmentView) this.f.getAttachmentsView()).addAttachment(uri);
    }

    public List<File> getAddedAttachments() {
        if (this.f.getAttachmentsView() == null || !(this.f.getAttachmentsView() instanceof AttachmentView)) {
            return null;
        }
        return ((AttachmentView) this.f.getAttachmentsView()).getAddedAttachments();
    }

    public List<Integer> getDeletedAttachmentIDs() {
        if (this.f.getAttachmentsView() == null || !(this.f.getAttachmentsView() instanceof AttachmentView)) {
            return null;
        }
        return ((AttachmentView) this.f.getAttachmentsView()).getDeletedAttachmentIDs();
    }

    public boolean isPopupValid() {
        if (!(this.f.getTitleView() instanceof PopupValid) || ((PopupValid) this.f.getTitleView()).isValid()) {
            if (!(this.f.getAttributesView() instanceof PopupValid) || ((PopupValid) this.f.getAttributesView()).isValid()) {
                if (!(this.f.getMediaView() instanceof PopupValid) || ((PopupValid) this.f.getMediaView()).isValid()) {
                    return !(this.f.getAttachmentsView() instanceof PopupValid) || ((PopupValid) this.f.getAttachmentsView()).isValid();
                }
                return false;
            }
            return false;
        }
        return false;
    }

    public void setEditMode(boolean z) {
        if (this.e != z) {
            this.e = z;
            InternalPopupListener internalPopupListener = this.g;
            if (internalPopupListener != null) {
                internalPopupListener.onChangedEditMode(z);
            }
            if (this.d != null) {
                if (!z || isEditable()) {
                    this.d.a(z);
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(InternalPopupListener internalPopupListener) {
        this.g = internalPopupListener;
    }

    public PopupListener getPopupListener() {
        return this.h;
    }

    public void setPopupListener(PopupListener popupListener) {
        this.h = popupListener;
    }
}
